<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head lang="en" th:replace="include/common/common :: commonHeader">
    <footer th:include="include/common/common :: layUiResource"></footer>
    <footer th:include="include/common/common :: blueCSSResource"></footer>

    <script>
        layui.config({
            base: '/staticResource/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index' , 'table'] , function () {
            var table = layui.table
                ,admin = layui.admin
                ,element = layui.element;

            let entityName = 'goods'
                ,pageSize = [[${pageSize}]]
                ,tableId = entityName + "-table-operate"
                ,cols = [
                [
                    {type:'checkbox', fixed: 'left'}
                    ,{field:'id', title: 'ID', sort: true, hide:true, fixed: 'left'}
                    ,{field:'code', sort:true , title: '商品代码'}
                    ,{field:'name', sort:true , title: '商品名称'}
                    ,{field:'barcode', sort:true , title: '条码'}
                    ,{field:'spec', sort:false , title: '单位'}
                    ,{field:'unit', sort:false , title: '包装单位'}
                    ,{field:'qpcStr', sort:false , title: '包装规格'}
                    ,{field:'clsCode', sort:false , title: '品类代码'}
                    ,{field:'clsItem.treeName', sort:false , title: '品类名称'}
                    ,{field:'brandCode', sort:false , title: '品牌代码'}
                    ,{field:'brandItem.name', sort:false , title: '品牌名称'}
                    ,{field:'oprice', sort:false , title: '售价'}
                    ,{title:'操作' , align:'center', width: 200 , fixed: 'right', toolbar: '#goods-table-operate-barDemo'}
                ]
            ];

            $(document).on('click' , '#' + entityName + 'SearchBtn' , function () {
                $.fn.blueJs.tools.active['layTable'].call(this , table , this , pageSize , cols , tableId);
            });

            $(document).ready(function () {
                let searchBtn = '#' + entityName + 'SearchBtn';
                $.fn.blueJs.tools.active['layTable'].call(this , table , searchBtn , pageSize , cols , tableId);
            });

            //监听工具条

            //todo:以下测试，未完成
            //监听表格复选框选择
            table.on('checkbox(goods-table-operate)', function(obj){
                console.log(obj)
            });

            table.on('tool(goods-table-operate)', function(obj){
                var data = obj.data;
                if(obj.event === 'detail'){
                    layer.alert('查看：<br>'+ JSON.stringify(data))
                    // layer.msg('ID：'+ data.id + ' 的查看操作');
                } else if(obj.event === 'del'){
                    layer.confirm('真的删除行么', function(index){
                        obj.del();
                        layer.close(index);
                    });
                } else if(obj.event === 'edit'){
                    let i = "/a/" + entityName + "/form?id=" + data.id , t = "编辑商品";
                    $.fn.blueJs.tools.active['layerOpen'].call(this , i , t);
                }
            });

            var active = {
                getCheckData: function(){ //获取选中数据
                    var checkStatus = table.checkStatus('goods-table-operate')
                        ,data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                }
                ,getCheckLength: function(){ //获取选中数目
                    var checkStatus = table.checkStatus('goods-table-operate')
                        ,data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                }
                ,add: function(){
                    layui.router();
                    let i = "/a/" + entityName + "/form?isNewRecord=true" , t = "参数信息";
                    $.fn.blueJs.tools.active['layerOpen'].call(this , i , t);
                }
            };

            $('.goods-table-operate-btn .layui-btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
    </script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">系统参数</div>
                <div class="layui-card-body">
                    <div class="layui-row layui-col-space10 layui-form-item">
                        <!--                        todo:id = entity + search + form-->
                        <form class="layui-form" id="goodsSearchForm" th:object="${goods}" method="post" action="/a/goods/findPage">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">商品名称：</label>
                                    <div class="layui-inline">
                                        <input type="text" name="name" id="searchgoodsName" placeholder="商品名称" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">商品代码：</label>
                                    <div class="layui-inline">
                                        <input type="text" name="code" id="searchgoodsCode" placeholder="商品代码" autocomplete="off" class="layui-input">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">商品条码：</label>
                                    <div class="layui-inline">
                                        <input type="text" name="barcode" id="searchgoodsBarcode" placeholder="商品条码" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <!--                        todo:blue-form-id = entity + search + form-->
                                <button type="button" class="layui-btn" id="goodsSearchBtn" onsubmit="return false" blue-form-id="goodsSearchForm">搜索</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </form>
                    </div>

                </div>
            </div>
            <div class="layui-card">
                <div class="layui-card-body" >
                    <div class="layui-btn-group goods-table-operate-btn" id="tableBtn" style="margin-bottom: 10px;">
                        <button class="layui-btn layui-btn-sm" data-type="add">新增</button>
                        <button class="layui-btn layui-btn-sm" data-type="getCheckData">获取选中行数据</button>
                        <button class="layui-btn layui-btn-sm" data-type="getCheckLength">获取选中数目</button>
                    </div>
                    <table class="layui-hide" id="goods-table-operate" lay-filter="goods-table-operate"></table>

                    <script type="text/html" id="goods-table-operate-barDemo">
                        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
                        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                    </script>
                </div>

            </div>
        </div>
    </div>
</div>
</body>
</html>